home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: beginner question
- Date: Sat, 30 Mar 96 21:13:54 GMT
- Organization: none
- Message-ID: <828220434snz@genesis.demon.co.uk>
- References: <4jc3sr$1ggu@uvaix3e1.comp.UVic.CA> <4jdo7l$de2@sparcserver.lrz-muenchen.de> <315AFED2.7466@willows.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <315AFED2.7466@willows.com>
- tarang@willows.com "Tarang Deshpande" writes:
-
- >Kurt Watzka wrote:
- >>
- >> struct FOO
- >> {
- >> int bar;
- >> }
- >>
- >> FOO is the "struct tag" of that struct, i.e. you can use it to declare
- >> variables of that type as in
- >>
- >> struct FOO s;
- >>
- >
- >So then what does the following mean:
- >
- >struct _FOO
-
- I assume you mean 'typedef struct _FOO' here otherwise what you write
- below is illegal.
-
- >{
- > int bar;
- >} FOO;
- >
- >struct _FOO s1;
- >FOO s2;
-
- struct _FOO is a type and is distinct from struct _BAR or struct _BAZ. typedef
- is a method for defining aliases for a type. So FOO above is simply an alias
- for struct _FOO. So given the definitions above
-
- FOO x;
-
- is just another way of writing:
-
- struct _FOO x;
-
- just as if you write:
-
- typedef int mytype;
-
- then:
-
- mytype y;
-
- is just another way of writing:
-
- int y;
-
- Structure tags are important if you want to create a self-referential
- or mutually referential structures e.g.
-
- struct elem {
- struct elem *next;
- int value;
- };
-
- You couldn't do this with a typedef because the typedef name wouldn't be
- in scope until after the definition i.e. you can't use it within it.
-
- Incidentally avoid identifiers that start with _ ; they are generally
- reserved by the language and invoke the undefined behaviour gods when you
- use them.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-